﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
namespace MyDefine
{
    public class BaseWindow : Window
    {
        #region 变量
        ControlTemplate baseWindowTemplate;
        #endregion

        #region 构造函数
        public BaseWindow()
        {
            this.Style = (Style)App.Current.Resources["BaseWindowStyle"];
            baseWindowTemplate = (ControlTemplate)App.Current.Resources["BaseWindowControlTemplate"];
            this.Loaded += load;
        }
        #endregion

        #region 事件
        private void load(object sender, RoutedEventArgs e)
        {
            #region 获取资源中的元素对象
            Button minBtn = (Button)baseWindowTemplate.FindName("btnMin", this);
            //Button maxBtn = (Button)baseWindowTemplate.FindName("btnMax", this);
            Button closeBtn = (Button)baseWindowTemplate.FindName("btnClose", this);
            Border border = (Border)baseWindowTemplate.FindName("borderTitle", this);
            #endregion

            #region 关闭、最大化/还原、最小化
            minBtn.Click += delegate
            {
                this.WindowState = WindowState.Minimized;
            };
            //maxBtn.Click += delegate
            //{
            //    if (this.WindowState == WindowState.Maximized)
            //    {
            //        this.WindowState = WindowState.Normal;
            //    }
            //    else
            //    {
            //        this.WindowState = WindowState.Maximized;
            //    }
            //};
            closeBtn.Click += delegate
            {
                this.Close();
            };
            #endregion

            #region 其他事件
            //边框拖拽
            border.MouseLeftButtonDown += delegate
            {
                this.DragMove();
            };
            #endregion
        }
        #endregion
    }
}
